/**
 * 
 */
package View;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;

import Model.contact;

/**
 * @author enzo
 *
 */
public class ContactCellRenderer extends JLabel implements ListCellRenderer {

	/**
	 * 
	 */
	public ContactCellRenderer() {
	    setOpaque(true);
	    setIconTextGap(12);
	    this.setBorder(BorderFactory.createLineBorder(Color.black));
	  }
	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		// TODO Auto-generated method stub
		
		
		contact Contact= (contact) value;
		
		//resizing the picture
		ImageIcon picture=new ImageIcon(Contact.getPhoto());
		picture.setImage(picture.getImage().getScaledInstance(75, 75, Image.SCALE_DEFAULT));
		setText(Contact.getFirstname()+ " "+Contact.getName());
		setIcon(picture);
		
		if (isSelected) {
		      setBackground(Color.GRAY);
		      setForeground(Color.white);
		    } else {
		      setBackground(Color.white);
		      setForeground(Color.black);
		    }
		    return this;
	}

}
